<template>
  <div class="app-container customer-div">
    <!--搜索-->
    <el-form :inline="true" :model="listQuery1" size="mini" label-width="80px" style="margin-top:40px;">
      <el-form-item label="员工姓名：">
        <el-input v-model="listQuery1.userName" placeholder="请输入关键字"></el-input>
      </el-form-item>
      <el-form-item>
        <el-button
          @click="handleSearchList1()"
          type="primary">
          查询
        </el-button>
        <el-button
          @click="showPop2('add','')"
          type="primary">
          新增
        </el-button>
        <el-button
          @click="showImport()"
          type="primary">
          导入
        </el-button>
        <exportPop ref="exportPop" @click.native="downloadExcel"></exportPop>
      </el-form-item>
    </el-form>


    <!--数据列表-->
    <div class="table-container">
      <el-table
        v-loading="listLoading1"
        :data="tableData1"
        border
        style="width: 100%; margin-top: 20px">
        <el-table-column
          label="被沟通人"
          min-width="100"
          align="center">
          <template slot-scope="scope">
              {{scope.row.userName}}
          </template>
        </el-table-column>

        <el-table-column
          label="沟通人"
          min-width="100"
          align="center">
          <template slot-scope="scope">
            {{scope.row.communicateUserName}}
          </template>
        </el-table-column>

        <el-table-column
          label="沟通时间"
          min-width="100"
          align="center">
          <template slot-scope="scope">
            {{scope.row.communicateTime}}
          </template>
        </el-table-column>

        <el-table-column
          label="沟通内容"
          min-width="200"
          align="center">
          <template slot-scope="scope">
            {{scope.row.content}}
          </template>
        </el-table-column>

        <el-table-column
          label="沟通结果"
          min-width="150"
          align="center">
          <template slot-scope="scope">
            {{scope.row.result}}
          </template>
        </el-table-column>


        <el-table-column
          label="下次沟通时间"
          min-width="100"
          align="center">
          <template slot-scope="scope">
              {{scope.row.nextCommunicateTime}}
          </template>
        </el-table-column>

        <el-table-column
          label="创建时间"
          min-width="150"
          align="center">
          <template slot-scope="scope">
            {{scope.row.createTime}}
          </template>
        </el-table-column>

        <el-table-column
          label="创建人"
          min-width="100"
          align="center">
          <template slot-scope="scope">
            {{scope.row.createUserName}}
          </template>
        </el-table-column>


        <el-table-column
          min-width="150"
          fixed="right"
          label="操作"
          align="center">
          <template slot-scope="scope">
            <el-button
              type="text"
              size="mini"
              @click="showPop2('edit',scope.row)">修改
            </el-button>

            <el-button
              type="text"
              size="mini"
              @click="delGT(scope.row)">删除
            </el-button>


          </template>
        </el-table-column>
      </el-table>
    </div>
    <div class="pagination-container">
      <el-pagination
        background
        @size-change="handleSizeChange1"
        @current-change="handleCurrentChange1"
        layout="total, sizes,prev, pager, next,jumper"
        :current-page.sync="listQuery1.pageNum"
        :page-size="listQuery1.pageSize"
        :page-sizes="[10,15,20]"
        :total="count1">
      </el-pagination>
    </div>
    <gtpop ref="gtpop" @getCommunicateListUser="handleSearchList1"></gtpop>
    <import-pop ref="importPop" @getList="handleSearchList1"></import-pop>
  </div>
</template>
<script>
import {communicateListUser,deleteCommunicate} from '@/api/company'
import gtpop from './components/gtpop.vue'
import store from '@/store'
import { mapGetters } from 'vuex'
import importPop from "./components/importPop";
import exportPop from "./components/exportPop";
const defaultListQuery1={
  pageNum: 1,
  pageSize: 10,
  userName: '',
};
export default {
  name: "index",
  components : {
    gtpop:gtpop,
    importPop,
    exportPop
  },
  data(){
    return {
      listQuery1: JSON.parse(JSON.stringify(defaultListQuery1)),
      tableData1: [],
      count1: 0,
      listLoading1: false,

    }
  },
  computed: {
    ...mapGetters([
      'name',
      'mobile',
      'userId'
    ]),

  },
  created() {
      this.getList1()
  },
  filters: {

  },
  methods:{
    downloadExcel(){
      this.$refs.exportPop.downloadExcel('exportUserCommunicate',this.listQuery1)
    },

    //显导入弹窗
    showImport(){
      this.$refs.importPop.showImport('importCommunicate','导入员工沟通记录','/api/user/communicate/download',)
    },

    //显示新增/编辑沟通记录
    showPop2(type,item){
      let form = {};
      if(type == 'add'){
        form = {}
      }else{
        form = JSON.parse(JSON.stringify(item))
      }
      this.$refs.gtpop.showPop2(type,form,'list')
    },

    //删除沟通
    delGT(item){
      this.$confirm('确认删除此记录吗？', '提示', {
        confirmButtonText: '确定',
        cancelButtonText: '取消',
        type: 'warning'
      }).then(() => {
        deleteCommunicate({communicateId:item.communicateId}).then(()=>{
          this.getList1();
          this.$message({
            type: 'success',
            message: '删除成功!'
          });
        })
      }).catch(() => {
        this.$message({
          type: 'info',
          message: '已取消删除'
        });
      });
    },

    //获取列表
    getList1() {
      this.listLoading = true;
      let listQuery = JSON.parse(JSON.stringify(this.listQuery1));
      communicateListUser(listQuery).then(response => {
        this.tableData1 = response.list;
        this.count1 = response.count;
        this.listLoading1 = false;
      }).catch(()=>{
        this.listLoading1 = false;
      });
    },

    handleSizeChange1(val){
      this.listQuery1.pageNum = 1;
      this.listQuery1.pageSize = val;
      this.getList1();
    },
    handleCurrentChange1(val){
      this.listQuery1.pageNum = val;
      this.getList1();
    },

    handleSearchList1(){
      this.listQuery1.pageNum = 1;
      this.getList1();
    },

  },
}
</script>

<style scoped lang="scss">

</style>
